package com.lepu.app.fun.grow.setting;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.app.config.UserConfig;
import com.app.utils.Const;
import com.core.lib.application.BaseFragmentActivity;
import com.eyzhs.app.R;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;

public class GrowSettingSpeedActivity extends BaseFragmentActivity implements
		OnTopbarNewLeftLayoutListener {

	RelativeLayout mSlowRelativeLayout;
	RelativeLayout mMiddleRelativeLayout;
	RelativeLayout mQuickRelativeLayout;

	@Override
	@SuppressLint("InflateParams")
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.grow_setting_speed_activity);

		init();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	private void init() {
		// topbar
		CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
		topbar.setTopbarTitle("设置播放速度");
		topbar.setonTopbarNewLeftLayoutListener(this);

		mSlowRelativeLayout = (RelativeLayout) findViewById(R.id.slowRelativeLayout);
		mMiddleRelativeLayout = (RelativeLayout) findViewById(R.id.middleRelativeLayout);
		mQuickRelativeLayout = (RelativeLayout) findViewById(R.id.quickRelativeLayout);

		int index = UserConfig.getConfigInt(this,
				Const.SETTING_SPEED_INDEX_SELECTED, 1);
		
		updateSpeed(index);
		
	}
	
	public void updateSpeed(int selectedIndex)
	{
		mSlowRelativeLayout.setSelected(false);
		mMiddleRelativeLayout.setSelected(false);
		mQuickRelativeLayout.setSelected(false);
		
		switch (selectedIndex) {
		case 0:
			mSlowRelativeLayout.setSelected(true);
			break;
		case 1:
			mMiddleRelativeLayout.setSelected(true);
			break;
		case 2:
			mQuickRelativeLayout.setSelected(true);
			break;

		default:
			break;
		}
	}

	public void layoutClick(View view) {

		int index = 0;
		
		int rid = view.getId();
		switch (rid) {
		case R.id.slowRelativeLayout:
			index = 0;
			break;
		case R.id.middleRelativeLayout:
			index = 1;
			break;
		case R.id.quickRelativeLayout:
			index = 2;
			break;
		default:
			break;
		}

		UserConfig.setConfig(this, Const.SETTING_SPEED_INDEX_SELECTED, index);
		updateSpeed(index);
	}

	@Override
	public void onBackPressed() {
		finish(true);
	}

	@Override
	public void onTopbarLeftLayoutSelected() {
		finish(true);
	}
}
